package com.zhuiyun.educations.api.courseprice.service.impl;

import com.github.pagehelper.PageHelper;
import com.zhuiyun.educations.api.courseprice.entity.Price;
import com.zhuiyun.educations.api.courseprice.mapper.CoursePriceMapper;
import com.zhuiyun.educations.api.courseprice.service.CoursePriceService;
import com.zhuiyun.educations.common.response.CommonResult;
import com.zhuiyun.educations.util.pageUtil.MybatisPageHelper;
import com.zhuiyun.educations.util.pageUtil.PageRequest;
import com.zhuiyun.educations.util.pageUtil.PageResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @ClassName CoursePriceServiceImpl
 * @Description TODO 课程价钱管理
 * @Author ys
 * @Date 2023/6/19 19:45
 **/
@Service
public class CoursePriceServiceImpl implements CoursePriceService {
    @Resource
    private CoursePriceMapper coursePriceMapper;
    /**
     * @Author ys
     * @Description TODO 分页查询
     * @Date 2023/6/26 14:09
     * @Return CommonResult
     * @param
     */
    @Override
    public CommonResult getPrice(PageRequest pageRequest,String courseTitle) {
        PageHelper.startPage(pageRequest);
        PageResult pageResult = MybatisPageHelper.getPageResult(coursePriceMapper.getPrice(pageRequest,courseTitle));
        return CommonResult.ok(pageResult);
    }
    /**
     * @Author ys
     * @Description TODO 新增
     * @Date 2023/6/26 14:09
     * @Return CommonResult
     * @param
     */
    @Override
    public CommonResult addPrice(Price price) {
        Date date =  new Date();
        price.setDelFlag(0);
        price.setCreateTime(date);
        price.setUpdateTime(date);
        return CommonResult.ok(coursePriceMapper.insertSelective(price));
    }
    /**
     * @Author ys
     * @Description TODO 修改
     * @Date 2023/6/26 14:09
     * @Return CommonResult
     * @param
     */
    @Override
    public  CommonResult updatePrice(Price price) {
        Date date =  new Date();
        price.setUpdateTime(date);
        return CommonResult.ok(coursePriceMapper.updateByPrimaryKeySelective(price));
    }
    /**
     * @Author ys
     * @Description TODO 逻辑删除
     * @Date 2023/6/26 14:09
     * @Return CommonResult
     * @param
     */
    @Override
    public CommonResult deletePriceById(int id) {
        return CommonResult.ok(coursePriceMapper.deletePriceById(id));
    }
    /**
     * @Author ys
     * @Description TODO 课程动态下拉
     * @Date 2023/6/26 14:09
     * @Return CommonResult
     * @param
     */
    @Override
    public CommonResult courseSelect() {
        return CommonResult.ok(coursePriceMapper.courseSelect());
    }

}
